package org.example.campsys.controller;

import org.apache.ibatis.annotations.Insert;
import org.example.campsys.model.*;
import org.example.campsys.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    public TeacherService teacherService;

    @RequestMapping("/addcourse")
    public Result addCourse(@RequestBody CourseInfo courseInfo){
        teacherService.addCourse(courseInfo);
        return Result.success("添加成功",true);
    }

    @RequestMapping("/selcourse")
    public Result selCourse(@RequestBody CourseInfo courseInfo){
        return Result.success("查询成功",teacherService.selCourse(courseInfo));
    }

    @RequestMapping("/delcourse")
    public Result delCourse(Integer id){
        teacherService.delCourse(id);
        return Result.success("删除成功",true);
    }

    @RequestMapping("/updcourse")
    public Result updCourse(@RequestBody CourseInfo courseInfo){
        if (StringUtils.hasLength(courseInfo.getCourseName()) && courseInfo.getActivityId() != null){
            teacherService.updCourse(courseInfo);
            return Result.success("修改成功",true);
        }
        return Result.fail("必填项不能为空",false);
    }

    @RequestMapping("/orccourse")
    public Result orcCourse(@RequestBody CourseInfo courseInfo){
        teacherService.orcCourse(courseInfo);
        return Result.success("开放或关闭成功",true);
    }

    @RequestMapping("/selclassstudent")
    public Result selClassStudent(Integer classId){
        return Result.success("查询成功",teacherService.selClassStudent(classId));
    }
    @RequestMapping("/addunit")
    public Result addUnit(@RequestBody UnitInfo unitInfo){
        if(StringUtils.hasLength(unitInfo.getUnitTitle())){
            teacherService.addUnit(unitInfo);
            return Result.success("添加成功",true);
        }
        return Result.fail("标题不能为空",false);
    }
    @RequestMapping("/orcunit")
    public Result orcUnit(@RequestBody UnitInfo unitInfo){
        teacherService.orcUnit(unitInfo);
        return Result.success("开放或关闭成功",true);
    }
    @RequestMapping("/updunit")
    public Result updUnit(@RequestBody UnitInfo unitInfo){
        teacherService.updUnit(unitInfo);
        return Result.success("修改成功",true);
    }
    @RequestMapping("/delunit")
    public Result delUnit(Integer id){
        teacherService.delUnit(id);
        return Result.success("删除成功",true);
    }
    @RequestMapping("/selunit")
    public Result selUnit(@RequestBody UnitInfo unitInfo){
        return Result.success("查询成功",teacherService.selUnit(unitInfo));
    }
    @RequestMapping("/selstudentunit")
    public Result selStudentUnit(@RequestBody LearningInfo learningInfo){
        return Result.success("查询成功",teacherService.selStudentUnit(learningInfo));
    }
    @RequestMapping("/evalute")
    public Result evaluate(@RequestBody EvaluationInfo evaluationInfo){
        if (evaluationInfo.getStuInClassId() != null){
            teacherService.evaluate(evaluationInfo);
            return Result.success("评价成功",true);
        }
        return Result.fail("id不能为空",false);
    }
    @RequestMapping("/posttask")
    public Result postTask(@RequestBody LearningInfo learningInfo){
        teacherService.postTask(learningInfo);
        return Result.success("发布成功",true);
    }
    @RequestMapping("/selmycourse")
    public Result selMyCourse(Integer loginId){
        return Result.success("查询成功",teacherService.selMyCourse(loginId));
    }

}
